#import <Foundation/Foundation.h>
#import <objc/runtime.h>

#import "FWDisplayObject.h"


@implementation FWDisplayObject

@synthesize key, objectVersion, updateRequired, summaryDisplay;


// ******************************************************************************************
#pragma mark -
#pragma mark Initialisation and object management

- (void)dealloc
{
    [key release];
    
    [super dealloc];
}

@end


// ******************************************************************************************
#pragma mark -
#pragma mark Object access from arrays

@implementation NSArray (FWDisplayObject)

- (id)fwDisplayObjectForKey:(NSString*)key
{
    NSUInteger count = self.count;
    for (NSUInteger i = 0; i < count; ++i) {
        FWDisplayObject* obj = [self objectAtIndex:i];
        if ([obj.key isEqualToString:key])
            return obj;
    }

    return nil;
}

- (NSUInteger)fwDisplayIndexForKey:(NSString*)key
{
    NSUInteger count = self.count;
    for (NSUInteger i = 0; i < count; ++i) {
        FWDisplayObject* obj = [self objectAtIndex:i];
        if ([obj.key isEqualToString:key])
            return i;
    }
    
    return NSNotFound;
}

@end